package com.course.base;

public class Student extends Person{
    private Course selectedCourse; // 所选课程
    private Teacher courseTeacher; // 授课教师
    // 子类构造方法：通过super()调用父类构造
    public Student(String studentId, String name, String gender) {
        super(studentId, name, gender);
    }
    // 学生“选课”方法
    public void selectCourse(Teacher teacher) {
        if (teacher.getTaughtCourse() != null) {
            this.selectedCourse = teacher.getTaughtCourse();
            this.courseTeacher = teacher;
            System.out.println("学生[" + super.name + "]成功选修课程：" + selectedCourse.getCourseName());
        } else {
            System.out.println("教师[" + teacher.name + "]暂未开课，无法选课");
        }
    }
    // 学生“退课”方法
    public void dropCourse() {
        if (selectedCourse != null) {
            System.out.println("学生[" + super.name + "]退选课程：" + selectedCourse.getCourseName());
            this.selectedCourse = null;
            this.courseTeacher = null;
        } else {
            System.out.println("学生[" + super.name + "]当前无课程");
        }
    }
    // 重写父类的printSheet：打印学生课表
    public void printSheet() {
            super.printSheet(); // 调用父类的printSheet
            if (selectedCourse != null && courseTeacher != null) {
                System.out.println("所选课程：" + selectedCourse.getCourseName());
                System.out.println("上课地点：" + selectedCourse.getLocation());
                System.out.println("上课时间：" + selectedCourse.getTime());
                System.out.println("授课教师：" + courseTeacher.name);
            } else {
                System.out.println("当前无选修课程");
            }
            System.out.println("======================\n");
    }
}
